package com.utils;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

import java.util.ResourceBundle;

public class JedisUtil {
    static JedisPool jp;
    static ResourceBundle bundle;
    static int maxIdle;
    static int maxTotal;
    static String host;
    static int port;
    static JedisPoolConfig jpc;
    static {
        bundle = ResourceBundle.getBundle("redis");
        maxIdle = Integer.parseInt(bundle.getString("maxIdle"));
        maxTotal = Integer.parseInt(bundle.getString("maxTotal"));
        host = bundle.getString("host");
        port = Integer.parseInt(bundle.getString("port"));
        jpc = new JedisPoolConfig();
        jpc.setMaxIdle(maxIdle);
        jpc.setMaxTotal(maxTotal);
        jp = new JedisPool(jpc,host,port);
    }
    public static Jedis getJedis(){
        return jp.getResource();
    }
}
